﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity.ModelConfiguration;
using CSP.Model.CSP;

namespace CSP.DataAccess.Mapping
{
    public class MapMap : EntityTypeConfiguration<Map>
    {
        public MapMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.LastModified)
                .IsRequired()
                .IsFixedLength()
                .HasMaxLength(8)
                .IsRowVersion();

            // Table & Column Mappings
            this.ToTable("Map");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.AddressId).HasColumnName("AddressId");
            this.Property(t => t.CenterPointX).HasColumnName("CenterPointX");
            this.Property(t => t.CenterPointY).HasColumnName("CenterPointY");
            this.Property(t => t.MarkerPointX).HasColumnName("MarkerPointX");
            this.Property(t => t.MarkerPointY).HasColumnName("MarkerPointY");
            this.Property(t => t.Zoom).HasColumnName("Zoom");
            this.Property(t => t.LastModified).HasColumnName("LastModified");

            // Relationships
            this.HasRequired(t => t.Address)
                .WithMany(t => t.Maps)
                .HasForeignKey(d => d.AddressId).WillCascadeOnDelete(true);

        }
    }
}
